package com.hdu.controller.contentManagement;


import com.hdu.entity.CourseBase;
import com.hdu.exception.ValidationGroups;
import com.hdu.pojo.PageBean;
import com.hdu.pojo.Result;
import com.hdu.service.ICourseBaseInfoService;
import com.hdu.util.UserUtils;
import com.hdu.vo.AddCourseVo;
import com.hdu.vo.CourseBaseInfoVo;
import com.hdu.vo.CourseParamVo;
import com.hdu.vo.EditCourseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/course")
@Api(value = "课程信息编辑接口", tags = "课程信息编辑接口")
public class CourseBaseInfoController {
    @Resource
    ICourseBaseInfoService courseBaseInfoService;

    @ApiOperation("课程查询接口")
    @PostMapping("/list")
    public Result<PageBean<CourseBase>> list(@RequestBody CourseParamVo courseParams) {
        Long companyId = UserUtils.getLoginUser().getCompanyId();
        return Result.success(courseBaseInfoService.queryCourseBaseList(companyId, courseParams));
    }

    @ApiOperation("新增课程基础信息接口")
    @PostMapping
    public Result<CourseBaseInfoVo> createCourseBase(@RequestBody @Validated(ValidationGroups.Insert.class) AddCourseVo addCourseVo) {
        Long companyId = UserUtils.getLoginUser().getCompanyId();
        return Result.success(courseBaseInfoService.createCourseBase(companyId, addCourseVo));
    }

    @ApiOperation("根据课程id查询课程基础信息")
    @GetMapping("/{courseId}")
    public Result<CourseBaseInfoVo> getCourseBaseById(@PathVariable Long courseId) {
        return Result.success(courseBaseInfoService.getCourseBaseInfo(courseId));
    }

    @ApiOperation("修改课程基础信息接口")
    @PutMapping
    public Result<CourseBaseInfoVo> modifyCourseBase(@RequestBody EditCourseVo editCourseDto) {
        Long companyId = UserUtils.getLoginUser().getCompanyId();
        return Result.success(courseBaseInfoService.updateCourseBase(companyId, editCourseDto));
    }

    @ApiOperation("删除课程")
    @DeleteMapping("/{courseId}")
    public void deleteCourse(@PathVariable Long courseId) {
        Long companyId = UserUtils.getLoginUser().getCompanyId();
        courseBaseInfoService.detectCourse(companyId, courseId);
    }
}
